Professional C++ by Marc Gregoire; Nicholas A. Solter; Scott J. Kleper

Professional C++ by Marc Gregoire; Nicholas A. Solter; Scott J. Kleper

Author:Marc Gregoire; Nicholas A. Solter; Scott J. Kleper
Language: eng
Format: mobi
Tags: Reference
ISBN: 9780470932445
Publisher: Wrox
Published: 2011-10-04T00:00:00+00:00


regex_search()

The regex_match() algorithm discussed in the previous section returns true if the entire source string matches the regular expression, false otherwise. It cannot be used to find a matching sub-string in the source string. The regex_search() algorithm allows you to search for a sub-string that matches a certain pattern in a source string. There are six versions of the regex_search() algorithm. The difference between them is in the type of arguments, similar to the six versions of regex_match(). See the Standard Library Reference resource on the website for more details.

One of the versions of the regex_search() algorithm accepts a begin and end iterator into a string that you want to process. You might be tempted to use this version of regex_search() in a loop to find all occurrences of a pattern in a source string by manipulating these begin and end iterators for each regex_search() call. Never do this! It can cause problems when your regular expression uses anchors (^ or $), word boundaries, and so on. It can also cause an infinite loop due to empty matches. Use the regex_iterator or regex_token_iterator as explained later in this chapter to extract all occurrences of a pattern from a source string.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.